<?php
			ob_start();			
?>
<?php
		
		if (isset($_COOKIE["user"])) {
			// if cookie <> ""
		  }
		  else
		  {
			  header("location:login.php");
			  
		  }
?>
<?php
                    if(isset($_POST["btnsubmit"]))
                    {
						$category=$_POST["txtcategory"];
						$public=$_POST["cbopublic"];
						$order=$_POST["txtorder"];
						@$uploadfile = escapeValue($_FILES["uploadfile"]["name"]);
						
							if($category=="")
							{
								errorMessage("S'il vous plaît catégorie d'entrée ...!");	
							}
							elseif($uploadfile=="")
							{
								errorMessage("S'il vous plaît sélectionner la photo ...!");	
							}
							else
							{
										//Upload Image
										$image_name = $_FILES["uploadfile"]["name"];
										$image_tmp_name = $_FILES["uploadfile"]["tmp_name"];
										$ext = "jpg";	
										$tag = "";
										$path = "category";
										
										// cate photo		
										$width = 184;
										$height = 211;			
										createImageAndThumb($image_tmp_name,$image_name,
															$width,
															$height,
															$tag,
															$path,
															$image_name);

										//end upload image
										
								$sql = "INSERT INTO tbl_category(cat_name,public, orders, photo) 
									VALUES('$category','$public', '$order','$image_name')";
						        if (query($sql))
								{
									errorMessage("Insérez catégorie de succès ...!");	
								}
							}
							
	
                    } 
                ?>

                	<div id="border_cont_title">
                        	<div id='content_title_left'>nouvelle catégorie</div>
                            <div id='content_title_right'></div>
					</div> <!--end border_cont_title-->
                    <?php echo @$errors;?>
                   <!--start table -->
                    <form action="index.php?page=categoryNew" method="post" enctype="multipart/form-data">
                    	<table width="760px">
                        	<tr>
                            	<td bgcolor="#FFEAD7"> Catégorie</td>
                                <td>
                               
                                	<input type="text" name="txtcategory" value="" size="40" />
                                </td>
                                
                            </tr>
                            <tr>
                            	<td bgcolor="#FFEAD7">Public</td>
                                <td>
                                	<select name="cbopublic" >
                                    	<option value="1">yes</option>
                                        <option value="0">no</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                            	<td bgcolor="#FFEAD7">Ordre</td>
                                <td><!--<input type="text" name="txtorder" value="<?php //echo $maxOrders; ?>" size="5" />-->
                                <?php
								if (empty($data["orders"])){
									$sql = "SELECT MAX(orders) FROM tbl_category LIMIT 1";	
									$rs = mysql_query($sql);
									$data["orders"] = 1 + mysql_result($rs,0);
								}
								?>
        						<input type="text" name="txtorder" value="<?php echo $data["orders"];?>" size="1" />
                                </td>
                            </tr>
                            <tr>
                            	<td align="left" height="30" bgcolor="#FFEAD7">Envoyer la photo*</td>
                                <td>
                                	<input class="submit" type="file" name="uploadfile" />
                                </td>
                            </tr>
                            <tr>
                            	<td bgcolor="#FFEAD7">Action</td>
                                <td>
                                
                                <input class="submit" type="submit" name="btnsubmit" value="Soumettre"  />
                                <input class="submit" type="button" name="btncancel" value="Annuler" onclick="redirect('index.php?page=category')" />

                                
                                </td>
                                
                            </tr>
                        </table>
                        </form>
                    <!--end table -->
                   
     